package com.mspbots.core.report.healthcheck;


import com.mspbots.core.report.service.HealthReportService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Log4j2
@EnableScheduling
@Component
public class HealthCheckSchedule {


    @Autowired
    private HealthReportService HealthReportService;


    //    @Scheduled(initialDelay = 5 * 60 * 1000,fixedDelay= 90 * 60 * 1000)
    public void HealthCheck() {
        HealthReportService.checkListTenant().parallelStream().forEach(detail -> {
            log.debug("tenant health check!! ");
            detail.setLastCheckTime(LocalDateTime.now());
            HealthReportService.tenantHealthCheck(detail);
            HealthReportService.saveOrUpdateHealth(detail);
        });
    }

}
